package ru.ssau.customerManagement.controller.remoting;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import java.util.List;

/**
 * Created by illabefat on 22.11.14.
 */
@XmlRootElement(name = "operationResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class OperationResponse implements Serializable {
    private static final long serialVersionUID = 5233679522041115343L;

    @XmlElement(name = "singleObject")
    private Object singleObject;

    @XmlElement(name = "object")
    @XmlElementWrapper(name = "objects")
    private List objects;

    @XmlElement(name = "exception")
    @XmlJavaTypeAdapter(ThrowableXmlAdapter.class)
    private Exception exception;

    public OperationResponse(){}
    public OperationResponse(Object object) {
        this(object, null);
    }

    public OperationResponse(Object object, Exception exception) {
        if (object instanceof List)
            this.objects = (List) object;
        else
            this.singleObject = object;
        this.exception = exception;
    }

    public Object getObject() {
        if (objects != null)
            return objects;
        else
            return singleObject;
    }

    public Object getSingleObject() {
        return singleObject;
    }

    public void setSingleObject(Object singleObject) {
        this.singleObject = singleObject;
    }

    public List getObjects() {
        return objects;
    }

    public void setObjects(List objects) {
        this.objects = objects;
    }

    public Exception getException() {
        return exception;
    }
    public void setException(Exception exception) {
        this.exception=exception;
    }
}
